package cn.rwklyd.BookKeeping.controller;

import cn.rwklyd.BookKeeping.pojo.Budget;
import cn.rwklyd.BookKeeping.pojo.Result;
import cn.rwklyd.BookKeeping.service.BudgetService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/budget")
@Tag(name = "预算管理", description = "预算的增删查改接口")
@Slf4j
public class BudgetController {

    @Autowired
    private BudgetService budgetService;

    @PostMapping("/add")
    @Operation(summary = "添加预算", description = "添加一个新的预算")
    public Result<String> addBudget(@RequestBody Budget budget) {
        log.info("添加预算: {}", budget);
        return budgetService.addBudget(budget);
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除预算", description = "根据ID删除预算")
    public Result<String> deleteBudget(@Parameter(description = "预算ID", required = true) @PathVariable Long id) {
        log.info("删除预算: {}", id);
        return budgetService.deleteBudget(id);
    }

    @PostMapping("/update")
    @Operation(summary = "更新预算", description = "更新预算信息")
    public Result<String> updateBudget(@RequestBody Budget budget) {
        log.info("更新预算: {}", budget);
        return budgetService.updateBudget(budget);
    }

    @GetMapping("/{id}")
    @Operation(summary = "获取预算", description = "根据ID获取预算详情")
    public Result<Budget> getBudgetById(@Parameter(description = "预算ID", required = true) @PathVariable Long id) {
        log.info("获取预算: {}", id);
        return budgetService.getBudgetById(id);
    }

    @GetMapping("/yearMonth")
    @Operation(summary = "按年月查询预算", description = "根据年月查询预算")
    public Result<List<Budget>> getBudgetsByYearMonth(
            @Parameter(description = "年份", required = true) @RequestParam Integer year,
            @Parameter(description = "月份", required = true) @RequestParam Integer month) {
        log.info("按年月查询预算: year={}, month={}", year, month);
        return budgetService.getBudgetsByYearMonth(year, month);
    }
} 